package io.zhengsh.payment.controller;

import com.fasterxml.jackson.databind.util.JSONPObject;
import io.zhengsh.payment.dto.PaymentDto;
import io.zhengsh.payment.dto.RefundPaymentDto;
import io.zhengsh.payment.vo.PaymentVo;
import io.zhengsh.payment.vo.RefundPaymentVo;
// import lombok.extern.slf4j.Slf4j;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.concurrent.TimeUnit;

/**
 * @author zhengsh
 */
@Slf4j
@RestController
@RequestMapping("/payment")
public class PaymentController {

    @PostMapping("/create")
    public PaymentVo create(@RequestBody @Validated PaymentDto paymentDto) throws InterruptedException {
        log.info("uri:/payment/create lang:{}", LocaleContextHolder.getLocale().getLanguage());
        PaymentVo vo = new PaymentVo();
        vo.setId(1L);
        vo.setCode("ORT0000001");

        TimeUnit.SECONDS.sleep(30);
        return vo;
    }


    @GetMapping("/refund")
    public RefundPaymentVo refund(RefundPaymentDto refundPaymentDto) {
        log.info("uri:/payment/refund orderCode: {}, refundAmount: {} ",
                refundPaymentDto.getOrderCode(), refundPaymentDto.getRefundAmount());
        RefundPaymentVo refundPaymentVo = new RefundPaymentVo();
        refundPaymentVo.setOrderCode(refundPaymentDto.getOrderCode());
        refundPaymentVo.setRefundAmount(refundPaymentDto.getRefundAmount());
        return refundPaymentVo;
    }
}